<?php


if(stripos($_SERVER["PHP_SELF"],"/rewrite.php/") !== false)
{
	$rewrite_open = true;
	define("REWRITE_OPEN",true);
}
else
{
	$rewrite_open = false;
}

$php_self=substr($_SERVER["PHP_SELF"],12);


if($rewrite_open)
{
	//有可能为空的参数，需要用[^\/]来判断，如果是肯定是数字用[0-9]
	$config["rewrite_rule"] = array(//规则：几个参数对应几个(.*?) ,如果没有/?也没有，分页的时候先replace(index.php,'/'),然后replace('.php','/')
		
		"\/tuijian\/id_([0-9]*)"=> array("id","/tuijian/tuijian_user.php",),
		"\/tuijian\/([0-9]*).html"=> array("p","/tuijian/index.php",),
	
		"\/user\/([0-9]*)"=> array("uid","/user/index.php",),
	
		"\/mblog\/detail_([0-9]*)"=> array("id","/mblog/detail.php",),
		"\/mblog\/index_?([0-9]*)_?([0-9]*)"=> array("tag_id","p","/mblog/index.php",),

		"\/meinv\/detail_([0-9]*)"=> array("id","/meinv/detail.php",),
		"\/meinv\/index_?([0-9]*)_?([0-9]*)"=> array("topic_id","p","/meinv/index.php",),
		"\/meinv\/user_([0-9]*)_?([0-9]*)"=> array("uid","p","/meinv/index.php",),
		
		"\/video\/detail_([0-9]*)"=> array("id","/video/detail.php",),
		"\/video\/index_?([0-9]*)_?([0-9]*)"=> array("p",'uid',"/video/index.php",),
		
		"\/want\/index_?([0-9]*)_?([0-9]*)"=> array("sex","p","/want/index.php",),
		"\/want\/user_?([0-9]*)_?([0-9]*)"=> array("uid","p","/want/index.php",),
	
		"\/sitemap_?([0-9]*)"=> array("p","/site_map.php",),
		
		"\/gonglue\/index_?([0-9]*)_?([0-9]*)"=> array("ct","p","/gonglue/index.php",),
		"\/gonglue\/detail_?([0-9]*)"=> array("id","/gonglue/detail.php",),
	);

	if(isset($_GET["rewrite_debug"]))
	{
		print_r($php_self);
	}
	foreach($config["rewrite_rule"] as $key => $rules)
	{
		if(preg_match("/^{$key}$/i",$php_self,$match))
		{
			
			$current_rewrite_rule = $rules;
			$rules_count = count($rules);
			foreach($rules as $get_key => $key_rule)
			{
				
				if($get_key == $rules_count-1)//最后一个
				{
					//echo $_SERVER['DOCUMENT_ROOT'] ."{$key_rule}";
					include_once($_SERVER['DOCUMENT_ROOT'] ."{$key_rule}");
				}
				else
				{
					if(strlen($match[$get_key+1])>0)$_GET["{$key_rule}"] = $match[$get_key+1];
				}
			}
			
		
		
		}
		
	
	}
}
else
{
	
	
	
	include_once($_SERVER['DOCUMENT_ROOT'] ."/index_default.php");
}







